<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <a-col :span="24">
            <a-form-model-item label="公司logo" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="logo">
              <j-image-upload isMultiple  v-model="model.logo" ></j-image-upload>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="公司简称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="name">
              <a-input v-model="model.name" placeholder="请输入公司简称"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="公司全称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="fullName">
              <a-input v-model="model.fullName" placeholder="请输入公司全称"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="所属行业" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="industryId">
              <a-input-number v-model="model.industryId" placeholder="请输入所属行业" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="所在行业" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="industryName">
              <a-input v-model="model.industryName" placeholder="请输入所在行业"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="人员规模" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="staffSize">
              <j-dict-select-tag type="list" v-model="model.staffSize" dictCode="staff_size" placeholder="请选择人员规模" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="企业性质" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="companyNature">
              <j-dict-select-tag type="list" v-model="model.companyNature" dictCode="company_nature" placeholder="请选择企业性质" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="公司简介" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="companyProfile">
              <a-textarea v-model="model.companyProfile" rows="4" placeholder="请输入公司简介" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="公司福利" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="welfare">
              <a-input v-model="model.welfare" placeholder="请输入公司福利"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="地址名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="addressName">
              <a-input v-model="model.addressName" placeholder="请输入地址名称"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="公司地址" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="address">
              <a-input v-model="model.address" placeholder="请输入公司地址"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="门牌号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="addressHouse">
              <a-input v-model="model.addressHouse" placeholder="请输入门牌号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="地址经度" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="longitude">
              <a-input v-model="model.longitude" placeholder="请输入地址经度"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="地址纬度" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="latitude">
              <a-input v-model="model.latitude" placeholder="请输入地址纬度"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="工作开始时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="startTime">
              <j-time placeholder="请选择工作开始时间"  v-model="model.startTime" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="工作结束时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="endTime">
              <j-time placeholder="请选择工作结束时间"  v-model="model.endTime" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="休息时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="restTime">
              <a-input v-model="model.restTime" placeholder="请输入休息时间"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="加班情况" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="workOvertime">
              <j-dict-select-tag type="list" v-model="model.workOvertime" dictCode="work_overtime" placeholder="请选择加班情况" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="公司相册，逗号分隔" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="album">
              <a-input v-model="model.album" placeholder="请输入公司相册，逗号分隔"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="营业执照" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="businessLicense">
              <j-image-upload isMultiple  v-model="model.businessLicense" ></j-image-upload>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="企业名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="realName">
              <a-input v-model="model.realName" placeholder="请输入企业名称"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="法人名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="legalPerson">
              <a-input v-model="model.legalPerson" placeholder="请输入法人名称"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="营业执照号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="identity">
              <a-input v-model="model.identity" placeholder="请输入营业执照号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="认证状态：0-默认，1-待审核，2-审核失败，3-审核通过" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="verifyStatus">
              <a-input-number v-model="model.verifyStatus" placeholder="请输入认证状态：0-默认，1-待审核，2-审核失败，3-审核通过" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="失败原因" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="refuseReason">
              <a-input v-model="model.refuseReason" placeholder="请输入失败原因"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="提交认证时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="addAuthTime">
              <j-date placeholder="请选择提交认证时间" v-model="model.addAuthTime"  style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="审核时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="authDate">
              <j-date placeholder="请选择审核时间" v-model="model.authDate"  style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="浏览数量" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="browseNumber">
              <a-input-number v-model="model.browseNumber" placeholder="请输入浏览数量" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="县级城市名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="city">
              <a-input v-model="model.city" placeholder="请输入县级城市名称"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="县级城市编码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="citycode">
              <a-input v-model="model.citycode" placeholder="请输入县级城市编码"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="市级城市名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="pcity">
              <a-input v-model="model.pcity" placeholder="请输入市级城市名称"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="市级城市编码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="pcitycode">
              <a-input v-model="model.pcitycode" placeholder="请输入市级城市编码"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="排序" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="sort">
              <a-input-number v-model="model.sort" placeholder="请输入排序" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="备注" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="remark">
              <a-input v-model="model.remark" placeholder="请输入备注"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="tenantId" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="tenantId">
              <a-input-number v-model="model.tenantId" placeholder="请输入tenantId" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="删除状态(0-正常,1-已删除)" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="delFlag">
              <a-input-number v-model="model.delFlag" placeholder="请输入删除状态(0-正常,1-已删除)" style="width: 100%" />
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>

  import { httpAction, getAction } from '@/api/manage'
  import { validateDuplicateValue } from '@/utils/util'

  export default {
    name: 'RmsCompanyForm',
    components: {
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        model:{
         },
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
        },
        url: {
          add: "/rms/rmsCompany/add",
          edit: "/rms/rmsCompany/edit",
          queryById: "/rms/rmsCompany/queryById"
        }
      }
    },
    computed: {
      formDisabled(){
        return this.disabled
      },
    },
    created () {
       //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
    },
    methods: {
      add () {
        this.edit(this.modelDefault);
      },
      edit (record) {
        this.model = Object.assign({}, record);
        this.visible = true;
      },
      submitForm () {
        const that = this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            httpAction(httpurl,this.model,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
            })
          }
         
        })
      },
    }
  }
</script>